/**
 * @file local_time.cpp
 * @brief Brief description of local_time.cpp
 * @author achdu0000@163.com
 * @version 1.0.0
 * @date 2024/07/07
 */

#include "local_time.h"
#include <string.h>

// ==================================================
// =============== PRE-DECLARE ======================
// ==================================================

LV_IMG_DECLARE(img_icon_gps_30x30)
LV_IMG_DECLARE(img_icon_earth_30x30)
LV_IMG_DECLARE(img_icon_moon_15x15)
LV_IMG_DECLARE(img_icon_people_20x20)

LV_FONT_DECLARE(lv_font_arial_bold_10)
LV_FONT_DECLARE(lv_font_yahei_bold_10)
LV_FONT_DECLARE(lv_font_yahei_bold_12)

extern lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(170, 200)];

// ==================================================
// =============== DEFINATIONS ======================
// ==================================================

// ==================================================
// =============== STATIC VARIABLES =================
// ==================================================

static uint8_t twenty_four_jieqi_val;
static uint8_t wuhou_val;

static uint8_t birth_twenty_four_jieqi_val;
static uint8_t birth_wuhou_val;

static uint8_t latitude_deg_val;
static uint8_t latitude_min_val;
static uint8_t latitude_sec_val;
static uint8_t longitude_deg_val;
static uint8_t longitude_min_val;
static uint8_t longitude_sec_val;

static uint8_t sunrise_hour_val;
static uint8_t sunrise_min_val;
static uint8_t sunset_hour_val;
static uint8_t sunset_min_val;

static const char *month_ganzhi_str = nullptr;

static uint8_t moonrise_hour_val;
static uint8_t moonrise_min_val;
static uint8_t moonset_hour_val;
static uint8_t moonset_min_val;

static uint16_t scale_width = 2;
static uint16_t scale_width_thick = 3;
static uint16_t scale_len = 22;
static lv_color_t scale_color = SCREEN_FG_COLOR;

static lv_color_t ellipse_color = lv_color_make(56, 87, 35);

// ==================================================
// =============== STATIC FUNCTION ==================
// ==================================================

// ==================================================
// =============== IMPLEMENTATION ===================
// ==================================================

static void local_time_meter_draw_event_cb(lv_event_t *e)
{
    LV_UNUSED(e);

    // LV_LOG_INFO("local_time_meter draw event finished");

    // lv_draw_ctx_t *draw_ctx = lv_event_get_draw_ctx(e);

    // lv_obj_t *meter = lv_event_get_target(e);
    // /* assuming `meter` is a standard circle */
    // LV_ASSERT(lv_obj_get_width(meter) == lv_obj_get_height(meter));
    // lv_coord_t meter_size_half = lv_obj_get_width(meter) / 2;

    // void *user_data = lv_event_get_user_data(e);
    // lv_area_t *meter_parent_coords = (lv_area_t *)(user_data);
    // // char bbuf[256] = {0};
    // // lv_snprintf(bbuf, sizeof(bbuf), "sent parent coords: (x1=%d, y1=%d),  (x2=%d, y2=%d)", meter_parent_coords->x1, meter_parent_coords->y1, meter_parent_coords->x2, meter_parent_coords->y2);
    // // LV_LOG_INFO(bbuf);
    // lv_coord_t meter_parent_width_half = (meter_parent_coords->x2 - meter_parent_coords->x1 + 1) / 2;
    // lv_coord_t meter_parent_height_half = (meter_parent_coords->y2 - meter_parent_coords->y1 + 1) / 2;

    // lv_draw_line_dsc_t line_dsc;
    // lv_draw_line_dsc_init(&line_dsc);
    // label_dsc.font = &lv_font_gb2312_ganzhi_12;

    // int16_t offset = 10;
    // for (uint8_t i = 0; i < 60; i++)
    // {
    //     /*
    //      *    |-`x`-| _
    //      *    |     / |
    //      *    |    /  |
    //      *    |`θ`/  `y`
    //      *    |  /    |
    //      *    | /     |
    //      *    |/      _
    //      */

    //     int16_t angle = 6 * i;
    //     int16_t x = meter_parent_width_half + lv_trigo_sin(angle) * (meter_size_half - offset) / LV_TRIGO_SIN_MAX;
    //     int16_t y = meter_parent_height_half - lv_trigo_cos(angle) * (meter_size_half - offset) / LV_TRIGO_SIN_MAX;

    //     // char buffer[265] = {0};
    //     // lv_snprintf(buffer, sizeof(buffer), "p_width_h=%d, p_height_h=%d, x=%d, y=%d", meter_parent_width_half, meter_parent_height_half, x, y);
    //     // LV_LOG_INFO(buffer);

    //     uint16_t text_width = lv_font_get_glyph_width(label_dsc.font, sixty_jiazi_strings[i + 1][0], sixty_jiazi_strings[i + 1][1]);
    //     uint16_t text_height = lv_font_get_line_height(label_dsc.font);

    //     lv_area_t label_coords;
    //     label_coords.x1 = x - (text_width / 2);
    //     label_coords.y1 = y - (text_height / 2);
    //     label_coords.x2 = label_coords.x1 + text_width;
    //     label_coords.y2 = label_coords.y1 + text_height;
    //     lv_draw_label(draw_ctx, &label_dsc, &label_coords, sixty_jiazi_strings[i + 1], NULL);

    // char buf[256] = {0};
    // lv_snprintf(buf, sizeof(buf), "i=%d, text=%s, x1=%d, y1=%d, x2=%d, y2=%d", i+1, sixty_jiazi_strings[i+1], label_coords.x1, label_coords.y1, label_coords.x2, label_coords.y2);
    // LV_LOG_INFO(buf);
    // }
}

bool set_jieqi_wuhou_val(const char *jieqi_str, uint8_t wuhou_index)
{
    /* asset jieqi_str in twenty four jieqi strings */

    uint8_t i = 0;
    size_t len = (sizeof(twenty_four_jieqi_text_table) / sizeof(twenty_four_jieqi_text_table[0]));

    for (; i < len && strcmp(twenty_four_jieqi_text_table[i], jieqi_str) != 0; i++)
    {
    }
    if (i == len || wuhou_index <= 0 || wuhou_index > 3)
        return false;
    twenty_four_jieqi_val = i;
    wuhou_val = wuhou_index;

    return true;
}

bool set_birth_jieqi_wuhou_val(const char *birth_jieqi_str, uint8_t birth_wuhou_index)
{
    /* asset birth_jieqi_str in twenty four jieqi strings */

    uint8_t i = 0;
    size_t len = (sizeof(twenty_four_jieqi_text_table) / sizeof(twenty_four_jieqi_text_table[0]));

    for (; i < len && strcmp(twenty_four_jieqi_text_table[i], birth_jieqi_str) != 0; i++)
    {
    }
    if (i == len || birth_wuhou_index <= 0 || birth_wuhou_index > 3)
        return false;
    birth_twenty_four_jieqi_val = i;
    birth_wuhou_val = birth_wuhou_index;

    return true;
}

bool set_local_gps_val(uint8_t longitude_deg, uint8_t longitude_min, uint8_t longitude_sec, uint8_t latitude_deg, uint8_t latitude_min, uint8_t latitude_sec)
{
    longitude_deg_val = longitude_deg;
    longitude_min_val = longitude_min;
    longitude_sec_val = longitude_sec;
    latitude_deg_val = latitude_deg;
    latitude_min_val = latitude_min;
    latitude_sec_val = latitude_sec;
    return true;
}

bool set_local_sunrise_and_sunset_val(uint8_t sunrise_hour, uint8_t sunrise_min, uint8_t sunset_hour, uint8_t sunset_min)
{
    sunrise_hour_val = sunrise_hour;
    sunrise_min_val = sunrise_min;
    sunset_hour_val = sunset_hour;
    sunset_min_val = sunset_min;
    return true;
}

bool set_local_moonrise_and_moonset_val(uint8_t moonrise_hour, uint8_t moonrise_min, uint8_t moonset_hour, uint8_t moonset_min)
{
    moonrise_hour_val = moonrise_hour;
    moonrise_min_val = moonrise_min;
    moonset_hour_val = moonset_hour;
    moonset_min_val = moonset_min;
    return true;
}

bool set_now_month_ganzhi(const char *month_ganzhi_s)
{
    month_ganzhi_str = month_ganzhi_s;
    char buf[128];
    lv_snprintf(buf, sizeof(buf), "%s", month_ganzhi_str);
    LV_LOG_INFO(buf);
    return true;
}

const char *get_now_month_ganzhi()
{
    return month_ganzhi_str;
    // return "月";
}

bool create_basic_twenty_four_jieqi_clock_ui(lv_obj_t *parent, lv_coord_t width, lv_coord_t height, lv_coord_t *content_w_ptr, lv_coord_t *content_h_ptr)
{
    lv_obj_t *indic_bg_boarder = lv_obj_create(parent);
    lv_coord_t bg_boader_width = scale_len + 2;
    lv_obj_set_size(indic_bg_boarder, width, height);
    lv_obj_set_style_bg_opa(indic_bg_boarder, LV_OPA_TRANSP, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_radius(indic_bg_boarder, LV_RADIUS_CIRCLE, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(indic_bg_boarder, bg_boader_width, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(indic_bg_boarder, SCREEN_TWENTY_FOUR_JIEQI_CIRCLR_BG_COLOR, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_center(indic_bg_boarder);

    lv_obj_t *meter = lv_meter_create(parent);
    lv_obj_set_size(meter, width, height);
    lv_obj_set_style_bg_opa(meter, LV_OPA_TRANSP, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_center(meter);

    /*Remove the circle from the middle of `meter`*/
    lv_obj_remove_style(meter, nullptr, LV_PART_INDICATOR);
    /*Remove the padding from `meter` (especially the padding between ticks and borader)*/
    lv_obj_set_style_pad_all(meter, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    lv_meter_scale_t *wh_scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, wh_scale, 73, scale_width, scale_len, scale_color);
    lv_meter_set_scale_range(meter, wh_scale, 0, 72, 360, 217.5);

    lv_meter_scale_t *jq_scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, jq_scale, 25, scale_width_thick, scale_len, scale_color);
    lv_meter_set_scale_range(meter, jq_scale, 0, 24, 360, 217.5);

    // lv_meter_scale_t *scale = lv_meter_add_scale(meter);
    // lv_meter_set_scale_ticks(meter, scale, 361, 0, 0, scale_color);
    // lv_meter_set_scale_range(meter, scale, 0, 360, 360, 217.5);

    lv_meter_indicator_t *arc_indic = lv_meter_add_arc(meter, wh_scale, scale_len, get_wuxing_color(twenty_four_jieqi_wuxing_table[twenty_four_jieqi_val]), 0);
    lv_meter_set_indicator_start_value(meter, arc_indic, twenty_four_jieqi_val * 3);
    lv_meter_set_indicator_end_value(meter, arc_indic, twenty_four_jieqi_val * 3 + wuhou_val);

    // lv_meter_set_indicator_start_value(meter, arc_indic, 42);
    // lv_meter_set_indicator_end_value(meter, arc_indic, 44);

    *content_w_ptr = width - 2 * bg_boader_width;
    *content_h_ptr = height - 2 * bg_boader_width;

    return true;
}

bool create_basic_gps_icon_and_label_ui(lv_obj_t *parent, lv_coord_t x_ofs, lv_coord_t y_ofs)
{
    lv_obj_t *label = lv_label_create(parent);
    lv_obj_set_style_text_font(label, &lv_font_arial_bold_10, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_label_set_text_fmt(label, "%d°%02d′%02d″E %d°%02d′%02d″N", longitude_deg_val, longitude_min_val, longitude_sec_val, latitude_deg_val, latitude_min_val, latitude_sec_val);
    lv_obj_align_to(label, parent, LV_ALIGN_CENTER, x_ofs, y_ofs);

    lv_obj_t *img = lv_img_create(parent);
    lv_img_set_src(img, &img_icon_gps_30x30);
    lv_obj_align_to(img, label, LV_ALIGN_OUT_LEFT_MID, 10, 0);

    return true;
}

bool create_extend_1_local_ellipse_and_earth_moon_ui_with_canvas(lv_obj_t *parent, lv_obj_t *canvas, lv_coord_t c_start_x, lv_coord_t c_start_y, lv_coord_t c_use_w, lv_coord_t c_use_h, lv_coord_t e_a, lv_coord_t e_b)
{

    lv_obj_align_to(canvas, parent, LV_ALIGN_CENTER, (CANVAS_WIDTH - c_use_w) / 2 - c_start_x, (CANVAS_HEIGHT - c_use_h) / 2 - c_start_y);

    lv_color_t e_color = lv_color_make(56, 87, 35);

    /* draw the earth ellipse */
    lv_coord_t center_x = c_start_x + c_use_w / 2;
    lv_coord_t center_y = c_start_y + c_use_h / 2;

    /*
     *    ← e_a →
     *    |-`x`-| _
     *    |     / |
     * ↑  |    /  |
     *e_b |`θ`/  `y`
     * ↓  |  /    |
     *    | /     |
     *    |/      _
     */
    lv_coord_t e_width = 4;

    int8_t angle;
    for (angle = 0; angle <= 90; angle++)
    {
        /* draw ellipse */
        for (lv_coord_t w = 0; w < e_width; w++)
        {
            lv_coord_t x = (e_a - w) * lv_trigo_sin(angle) / LV_TRIGO_SIN_MAX;
            lv_coord_t y = (e_b - w) * lv_trigo_cos(angle) / LV_TRIGO_SIN_MAX;

            /* Top-left corner of the ellipse border */
            lv_canvas_set_px_color(canvas, center_x + x, center_y + y, e_color);
            lv_canvas_set_px_opa(canvas, center_x + x, center_y + y, LV_OPA_COVER);
            /* Bottom-left corner of the ellipse border */
            lv_canvas_set_px_color(canvas, center_x - x, center_y + y, e_color);
            lv_canvas_set_px_opa(canvas, center_x - x, center_y + y, LV_OPA_COVER);
            /* Top-right corner of the ellipse border */
            lv_canvas_set_px_color(canvas, center_x + x, center_y - y, e_color);
            lv_canvas_set_px_opa(canvas, center_x + x, center_y - y, LV_OPA_COVER);
            /* Bottom-right corner of the ellipse border */
            lv_canvas_set_px_color(canvas, center_x - x, center_y - y, e_color);
            lv_canvas_set_px_opa(canvas, center_x - x, center_y - y, LV_OPA_COVER);
        }

        /* you can use some Anti-Aliasing Algorithm to make it more beatiful */

        // for (int8_t angle = 0; angle <= 90; angle++)
        // {
        //     lv_coord_t x = e_a * lv_trigo_sin(angle) / LV_TRIGO_SIN_MAX;
        //     lv_coord_t y = e_b * lv_trigo_cos(angle) / LV_TRIGO_SIN_MAX;

        //     uint8_t repeat_times = 10;
        //     /* Draw the border */
        //     for (uint8_t rt = 0; rt < repeat_times; rt++)
        //     {
        //         lv_coord_t x_ofs = (rt + 0.5) * (e_a - x) / e_a;
        //         lv_coord_t y_ofs = (rt + 0.5) * (e_b - y) / e_b;

        //         /* Top-left corner of the ellipse border */
        //         lv_canvas_set_px_color(canvas, center_x + x + x_ofs, center_y + y + y_ofs, e_color);
        //         lv_canvas_set_px_opa(canvas, center_x + x + x_ofs, center_y + y + y_ofs, LV_OPA_COVER);
        //         /* Bottom-left corner of the ellipse border */
        //         lv_canvas_set_px_color(canvas, center_x - x - x_ofs, center_y + y + y_ofs, e_color);
        //         lv_canvas_set_px_opa(canvas, center_x - x - x_ofs, center_y + y + y_ofs, LV_OPA_COVER);
        //         /* Top-right corner of the ellipse border */
        //         lv_canvas_set_px_color(canvas, center_x + x + x_ofs, center_y - y - y_ofs, e_color);
        //         lv_canvas_set_px_opa(canvas, center_x + x + x_ofs, center_y - y - y_ofs, LV_OPA_COVER);
        //         /* Bottom-right corner of the ellipse border */
        //         lv_canvas_set_px_color(canvas, center_x - x - x_ofs, center_y - y - y_ofs, e_color);
        //         lv_canvas_set_px_opa(canvas, center_x - x - x_ofs, center_y - y - y_ofs, LV_OPA_COVER);
        //     }
        // }
    }
    /* scan and fill (simply) the pionts should be in the ellipse */
    for (lv_coord_t i = 1; i < CANVAS_WIDTH - 1; i++)
    {
        for (lv_coord_t j = 1; j < CANVAS_HEIGHT - 1; j++)
        {

            if (lv_canvas_get_px(canvas, i, j).full != e_color.full &&
                ((lv_canvas_get_px(canvas, i - 1, j).full == e_color.full && lv_canvas_get_px(canvas, i + 1, j).full == e_color.full) ||
                 (lv_canvas_get_px(canvas, i, j - 1).full == e_color.full && lv_canvas_get_px(canvas, i, j + 1).full == e_color.full)))
            {
                lv_canvas_set_px_color(canvas, i, j, e_color);
                lv_canvas_set_px_opa(canvas, i, j, LV_OPA_COVER);
            }
        }
    }

    /* draw tick lines */
    lv_coord_t l_len = 6;
    for (angle = 0; angle <= 90; angle += 15)
    {

        static lv_point_t points[8];
        lv_draw_line_dsc_t line_dsc;
        lv_draw_line_dsc_init(&line_dsc);
        line_dsc.color = ((angle % 45 == 0) ? lv_color_make(0, 0, 255) : lv_color_make(68, 114, 196));
        line_dsc.opa = LV_OPA_COVER;
        line_dsc.width = 2;
        if (angle == 0)
        {
            points[0].x = center_x;
            points[0].y = center_y - e_b - l_len / 2;
            points[1].x = center_x;
            points[1].y = center_y - e_b + l_len / 2;

            points[2].x = center_x;
            points[2].y = center_y + e_b - l_len / 2;
            points[3].x = center_x;
            points[3].y = center_y + e_b + l_len / 2;

            lv_canvas_draw_line(canvas, points, 2, &line_dsc);
            lv_canvas_draw_line(canvas, points + 2, 2, &line_dsc);
        }
        else if (angle == 90)
        {
            points[0].x = center_x - e_a - l_len / 2;
            points[0].y = center_y;
            points[1].x = center_x - e_a + l_len / 2;
            points[1].y = center_y;

            points[2].x = center_x + e_a - l_len / 2;
            points[2].y = center_y;
            points[3].x = center_x + e_a + l_len / 2;
            points[3].y = center_y;

            lv_canvas_draw_line(canvas, points, 2, &line_dsc);
            lv_canvas_draw_line(canvas, points + 2, 2, &line_dsc);
        }
        else
        {
            lv_coord_t y = e_b * lv_trigo_cos(angle) / LV_TRIGO_SIN_MAX;
            lv_coord_t x = e_a * lv_trigo_sin(angle) / LV_TRIGO_SIN_MAX;

            points[0].x = center_x + x - l_len / 2;
            points[0].y = center_y - y + l_len / 2;
            points[1].x = center_x + x + l_len / 2;
            points[1].y = center_y - y - l_len / 2;

            points[2].x = center_x + x - l_len / 2;
            points[2].y = center_y + y - l_len / 2;
            points[3].x = center_x + x + l_len / 2;
            points[3].y = center_y + y + l_len / 2;

            points[4].x = center_x - x + l_len / 2;
            points[4].y = center_y - y + l_len / 2;
            points[5].x = center_x - x - l_len / 2;
            points[5].y = center_y - y - l_len / 2;

            points[6].x = center_x - x + l_len / 2;
            points[6].y = center_y + y - l_len / 2;
            points[7].x = center_x - x - l_len / 2;
            points[7].y = center_y + y + l_len / 2;

            lv_canvas_draw_line(canvas, points, 2, &line_dsc);
            lv_canvas_draw_line(canvas, points + 2, 2, &line_dsc);
            lv_canvas_draw_line(canvas, points + 4, 2, &line_dsc);
            lv_canvas_draw_line(canvas, points + 6, 2, &line_dsc);
        }
    }

    /* draw earth and moon */
    lv_obj_t *earth_img = lv_img_create(parent);
    lv_img_set_src(earth_img, &img_icon_earth_30x30);
    lv_obj_align_to(earth_img, parent, LV_ALIGN_CENTER, -75, 22);

    lv_obj_t *moon_img = lv_img_create(parent);
    lv_img_set_src(moon_img, &img_icon_moon_15x15);
    lv_img_set_angle(moon_img, 3150);
    lv_obj_align_to(moon_img, earth_img, LV_ALIGN_OUT_LEFT_MID, 5, 8);

    return true;
}

bool create_extend_1_local_time_connect_people_ui(lv_obj_t *parent, lv_coord_t border_radius)
{
    /* draw [icon people] */
    lv_coord_t r = LV_MAX(border_radius - 13, 1);
    lv_obj_t *img_people = lv_img_create(parent);
    lv_img_set_src(img_people, &img_icon_people_20x20);

    lv_coord_t angle = birth_twenty_four_jieqi_val * 15 + (birth_wuhou_val - 1) * 5;
    angle -= 53;
    if (angle < 0)
        angle += 360;
    lv_img_set_angle(img_people, angle * 10);
    angle += 2;
    lv_coord_t x_ofs = r * lv_trigo_cos(90 - angle) / LV_TRIGO_SIN_MAX;
    lv_coord_t y_ofs = -r * lv_trigo_sin(90 - angle) / LV_TRIGO_SIN_MAX;
    lv_obj_align_to(img_people, parent, LV_ALIGN_CENTER, x_ofs, y_ofs);

    /* draw [icon earth] */
    lv_obj_t *img_earth = lv_img_create(parent);
    lv_img_set_src(img_earth, &img_icon_earth_30x30);
    // lv_img_set_zoom(img_earth, 256 >> 1);

    angle = twenty_four_jieqi_val * 15 + (wuhou_val - 1) * 5;
    angle -= 53;
    if (angle < 0)
        angle += 360;
    lv_img_set_angle(img_earth, angle * 10);
    angle -= 1;
    x_ofs = r * lv_trigo_cos(90 - angle) / LV_TRIGO_SIN_MAX;
    y_ofs = -r * lv_trigo_sin(90 - angle) / LV_TRIGO_SIN_MAX;
    lv_obj_align_to(img_earth, parent, LV_ALIGN_CENTER, x_ofs, y_ofs);

    return true;
}

bool create_extend_2_local_sunrise_and_sunset_ui(lv_obj_t *parent, lv_coord_t x_ofs, lv_coord_t y_ofs)
{
    lv_obj_t *label = lv_label_create(parent);
    lv_obj_set_style_text_font(label, &lv_font_yahei_bold_10, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(label, lv_color_make(192, 0, 0), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_label_set_text_fmt(label, "日出 %02d:%02d\n日落 %02d:%02d", sunrise_hour_val, sunrise_min_val, sunset_hour_val, sunset_min_val);
    lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_align_to(label, parent, LV_ALIGN_CENTER, x_ofs, y_ofs);
    return true;
}

bool create_extend_2_local_moonrise_and_moonset_ui(lv_obj_t *parent, lv_coord_t x_ofs, lv_coord_t y_ofs)
{
    lv_obj_t *label = lv_label_create(parent);
    lv_obj_set_style_text_font(label, &lv_font_yahei_bold_10, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(label, lv_color_white(), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_label_set_text_fmt(label, "月出 %02d:%02d\n月落 %02d:%02d", moonrise_hour_val, moonrise_min_val, moonset_hour_val, moonset_min_val);
    lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_align_to(label, parent, LV_ALIGN_CENTER, x_ofs, y_ofs);
    return true;
}

bool create_extend_2_month_ganzhi_label_ui(lv_obj_t *parent, lv_coord_t x_ofs, lv_coord_t y_ofs)
{
    lv_obj_t *label = lv_label_create(parent);
    lv_label_set_text_fmt(label, "【地时-月】\n%s", get_now_month_ganzhi());
    lv_obj_set_style_text_font(label, &lv_font_yahei_bold_12, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(label, lv_color_make(112, 48, 160), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_align_to(label, parent, LV_ALIGN_CENTER, x_ofs, y_ofs);
    return true;
}
